#include "InputHangdler.h"
#include "Game.h"
#include "Player.h"

InputHangdler* InputHangdler::m_pInstance = 0;

InputHangdler::InputHangdler()
{
	m_bButtonDown = true;
	// nothing for now
}

InputHangdler::~InputHangdler()
{
	// do nothing
}


void InputHangdler::update()
{
	SDL_Event event;
	while (SDL_PollEvent(&event))
	{
		switch (event.type)
		{
		case SDL_QUIT:
			TheGame::Instance()->quit();
			break;
		case SDL_MOUSEBUTTONDOWN:
			onMouseButtonDown(event);
			m_bButtonDown = true;
			break;
		case SDL_MOUSEMOTION :
			onMouseMove(event);
			break;
		case SDL_MOUSEBUTTONUP:
			onMouseButtonUp(event);
			m_bButtonDown = false;
			break;
		case SDL_KEYDOWN:
			onKeyDown(event);
			break;
		case SDL_KEYUP:
			onKeyUp();
			break;
		default:
			break;
		}
	}
}

void InputHangdler::onKeyDown(SDL_Event &event)
{
	m_keyCode = event.key.keysym.sym;
}

SDL_Keycode InputHangdler::getKeyCode()
{
	return m_keyCode;
}

Point InputHangdler::getMousePossition()
{
	return m_mousePossition;
}

Point InputHangdler::getMousePossitionMove()
{
	return m_mousePossitionMove;
}

void InputHangdler::onKeyUp()
{
	// do nothing for now
}

void InputHangdler::onMouseMove(SDL_Event &event)
{
	m_mousePossitionMove.x = event.button.x;
	m_mousePossitionMove.y = event.button.y;
}

void InputHangdler::onMouseButtonDown(SDL_Event &event)
{
	m_mousePossition.x = event.motion.x;
	m_mousePossition.y = event.motion.y;
}

void InputHangdler::onMouseButtonUp(SDL_Event &event)
{
	m_bButtonDown = false;
}

void InputHangdler::isKeyDown()
{
	m_keyCode = NULL;
	m_mousePossitionMove = { -1, -1 };
	m_mousePossition = { -1, -1 };
}

void InputHangdler::resetMouseDown(int &a)
{
	if (a == 1)
		m_bButtonDown = true;
	if (a == 0)
		m_bButtonDown = false;
}

bool InputHangdler::getResetMouseDown()
{
	return m_bButtonDown;
}